package com.forum.controller;

import com.forum.common.api.CommonResult;
import com.forum.common.constant.PostConstants;
import com.forum.model.dto.PostAuditDTO;
import com.forum.model.vo.PostVO;
import com.forum.service.PostAuditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 帖子审核控制器
 */
@Tag(name = "帖子审核接口")
@RestController
@RequestMapping("/audit")
@RequiredArgsConstructor
public class PostAuditController {
    
    private final PostAuditService postAuditService;
    
    @Operation(summary = "获取待审核帖子列表")
    @GetMapping("/pending")
    public CommonResult<List<PostVO>> getPendingPosts() {
        return CommonResult.success(postAuditService.getPendingPosts());
    }
    
    @Operation(summary = "审核通过帖子")
    @PostMapping("/{id}/approve")
    public CommonResult<PostVO> approvePost(
            @PathVariable Long id,
            @RequestParam Long auditorId,
            @RequestParam(required = false) String remark) {
        return CommonResult.success(postAuditService.approvePost(id, auditorId, remark));
    }
    
    @Operation(summary = "拒绝帖子发布")
    @PostMapping("/{id}/reject")
    public CommonResult<PostVO> rejectPost(
            @PathVariable Long id,
            @RequestParam Long auditorId,
            @RequestParam String reason) {
        return CommonResult.success(postAuditService.rejectPost(id, auditorId, reason));
    }
    
    @Operation(summary = "批量审核帖子")
    @PostMapping("/batch")
    public CommonResult<Void> batchAudit(@RequestBody List<PostAuditDTO> auditDTOs) {
        // TODO: 实现批量审核
        return CommonResult.success(null);
    }
    
    @Operation(summary = "获取特定状态的帖子列表")
    @GetMapping("/status/{status}")
    public CommonResult<List<PostVO>> getPostsByStatus(@PathVariable Integer status) {
        return CommonResult.success(postAuditService.getPostsByStatus(status));
    }
    
    @Operation(summary = "获取已发布帖子列表")
    @GetMapping("/published")
    public CommonResult<List<PostVO>> getPublishedPosts() {
        return CommonResult.success(postAuditService.getPostsByStatus(PostConstants.STATUS_PUBLISHED));
    }
    
    @Operation(summary = "获取拒绝发布的帖子列表")
    @GetMapping("/rejected")
    public CommonResult<List<PostVO>> getRejectedPosts() {
        return CommonResult.success(postAuditService.getPostsByStatus(PostConstants.STATUS_REJECTED));
    }
    
    @Operation(summary = "获取用户所有帖子")
    @GetMapping("/user/{userId}")
    public CommonResult<List<PostVO>> getUserAllPosts(@PathVariable Long userId) {
        return CommonResult.success(postAuditService.getUserAllPosts(userId));
    }
} 